package com.yjhb.android.sbz.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.yjhb.android.sbz.R;
import com.jojo.android.zxlib.base.BaseRecyclerAdapter;
import com.jojo.android.zxlib.view.DrawHookView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 创建者 zx
 * 创建时间 2021/1/30 14:53
 */
public class SubjectAdapter extends BaseRecyclerAdapter<SubjectAdapter.Holder, String> {
    private final String TAG = "SubjectAdapter";

    int selectIndex = -1;

    public SubjectAdapter(Context context) {
        super(context);
    }

    @Override
    protected Holder getHolder(View v) {
        return new Holder(v);
    }

    @Override
    public void setData(List<String> strings) {
        selectIndex = -1;
        super.setData(strings);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.item_subject;
    }


    @Override
    public void onBindViewHolder(@NonNull Holder holder, int position) {
        if (position == selectIndex) {
            holder.selectedTv.setTextColor(Color.RED);
            holder.hook.setVisibility(View.VISIBLE);
            holder.hook.setColor(Color.RED);
            holder.hook.refresh();
        } else {
            holder.selectedTv.setTextColor(Color.BLACK);
            holder.hook.setVisibility(View.INVISIBLE);
        }
        char i = (char) (65 + position);
        holder.selectedTv.setText(i + " " + entity);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                selectIndex = position;
                notifyDataSetChanged();
            }
        });
    }

    public int getSelectIndex(){
        return selectIndex;
    }

    class Holder extends RecyclerView.ViewHolder {
        @BindView(R.id.selected_tv)
        TextView selectedTv;
        @BindView(R.id.hook)
        DrawHookView hook;

        public Holder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

}
